package com.aaa.controller;

import com.aaa.entity.Log;
import com.aaa.entity.LogPageSort;
import com.aaa.entity.MyReturn;
import com.aaa.service.LogService;
import com.aaa.util.MyTools;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ：admin
 * @date ：Created in 2022/7/5 18:00
 * @description：
 * @modified By：
 */
@Controller
@RequestMapping("log")
public class LogController {

    @Autowired
    private LogService logService;

    MyReturn myReturn = new MyReturn();

    /**
     * 跳转到显示所有用户的页面
     *
     * @return String
     */
    @RequestMapping("toShowLogPage.do")
    public String toShowUserPage() {
        return "showLog";
    }

    /**
     * 分页查询所有日志信息
     *
     * @param logPageSort
     * @return
     */
    @RequestMapping("findAllLogPage.do")
    @ResponseBody
    public MyReturn findAllLogPage(LogPageSort logPageSort) {
        Page<Log> page = logService.findAllLog(logPageSort);
        //获取总条数
        myReturn.setCount(page.getTotal());
        //获取数据
        myReturn.setData(page.getResult());
        MyTools.getSuccessResult(myReturn);
        return myReturn;
    }

    @RequestMapping("saveLog.do")
    @ResponseBody
    public MyReturn saveLog(Log log){
        int saveNum = logService.saveLog(log);
        if (saveNum > 0){
            MyTools.getSuccessResult(myReturn);
        } else {
            MyTools.getFailResult(myReturn);
        }
        return myReturn;
    }



}
